public class Tesr {
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();

        for(int i =0; i<s.length();i++) {
            char ch = s.charAt(i);

            if(ch == '[' || ch == '{' || ch == '(') {
                stack.push(ch);
            }else {
                //遇到右括号
                if(stack.empty()) {
                    return false;
                }

                char z = stack.peek();
                if(z == '(' && ch == ')' || z == '[' && ch == ']' || z == '{' && ch == '}') {
                    stack.pop();
                }else {
                    return false;
                }
            }
        }
        if( !stack.empty()) {
            return false;
        }
        return true;
    }
    public boolean IsPopOrder (int[] pushV, int[] popV) {
        // write code here
        Stack<Integer> stack = new Stack<>();
        int j = 0;
        for(int i = 0; i < pushV.length;i++) {
            stack.push(pushV[i]);

            while( j < popV.length &&
                    !stack.empty() &&
                    stack.peek() == popV[j]) {
                stack.pop();
                j++;
            }
        }
        if(j < popV.length) {
            return false;
        }
        return true;
    }
}
